﻿using System;
using System.Linq;
using System.Linq.Expressions;

namespace VirtualTournaments.Data.DataMappers
{
    public abstract class AbstractDataMapper<T>
    {
        internal protected T[] GetList()
        {
            return GetList(null);
        }

        internal protected T[] GetList(Expression<Func<T, bool>> whereExpression)
        {
            IQueryable<T> dataSource = GetDataSource();
            if (whereExpression != null)
                dataSource = dataSource.Where(whereExpression);
            return dataSource.ToArray();
        }

        internal protected void Save(T toSave)
        {
        }

        internal protected abstract IQueryable<T> GetDataSource();
    }
}
